﻿#include "FITKAbaqusAdaptorInteractionProperty.h"
#include "InpKeyLineSpliter.h"
#include "FITKAbaqusINPReader.h"
#include "FITKAbaqusINPWriter.h"
#include "FITKAbaqusAdaptorInteractionPropertySurfaceContact.h"
#include "FITK_Component/FITKAbaqusData/FITKAbaqusPart.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaConstraintCoupling.h" 
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaConstraintTie.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaAssembly.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaAbstractInteraction.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaInteractionManager.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaInteractionPropertyManager.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaInteractionPropertyContact.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaInteractionContactTangentialBehavior.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaInteractionContactNormalBehavior.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaInteractionContactBehavior.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaInteractionSurfToSurfExplicit.h"
#include "FITK_Component/FITKAbaqusData/FITKDataCase.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaStepManager.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaAbstractStep.h"
#include <QDebug>
//命名空间
namespace IO
{
    QString FITKAbaqusAdaptorInteractionProperty::getAdaptorClass()
    {
        return "IO::FITKAbaqusAdaptorInteractionProperty";
    }

    void FITKAbaqusAdaptorInteractionProperty::setCaseData(AbaqusData::FITKDataCase* caseData)
    {
        _caseData = caseData;
    }

    bool FITKAbaqusAdaptorInteractionProperty::adaptR()
    {
        //读取
        Interface::FITKAbaAbstractInteractionProperty* iteractionProp = dynamic_cast<Interface::FITKAbaAbstractInteractionProperty*>(_dataObj);
        if (!iteractionProp || !_reader || !_caseData) return false;
        bool readOk = false;
        //获取类型
        Interface::FITKAbaAbstractInteractionProperty::FITKAbaInteractionPropertyType type = iteractionProp->getInteractionPropertyType();
        if (type == Interface::FITKAbaAbstractInteractionProperty::FITKAbaInteractionPropertyType::Contact)
            readOk = this->readInteractionPropertyContact();

        return readOk;
    }

    bool FITKAbaqusAdaptorInteractionProperty::adaptW()
    {
        //写出
        Interface::FITKAbaAbstractInteractionProperty* iteractionProp = dynamic_cast<Interface::FITKAbaAbstractInteractionProperty*>(_dataObj);
        if (!iteractionProp || !_writer || !_caseData) return false;
        bool writerOK = false;
        //获取类型
        Interface::FITKAbaAbstractInteractionProperty::FITKAbaInteractionPropertyType type = 
            iteractionProp->getInteractionPropertyType();
        if (type == Interface::FITKAbaAbstractInteractionProperty::FITKAbaInteractionPropertyType::Contact)
            writerOK = this->writeInteractionPropertyContact();
        return  writerOK;
    }

    bool FITKAbaqusAdaptorInteractionProperty::readInteractionPropertyContact()
    {
        //通过工厂创建
        auto adaptor = new FITKAbaqusAdaptorInteractionPropertySurfaceContact;
        if (adaptor == nullptr)
        {
            return false;
        }
        //设置读取器
        adaptor->setFileReader(_reader);
        adaptor->setDataObject(_dataObj);
        adaptor->setCaseData(_caseData);
        bool ok = adaptor->adaptR();

        delete adaptor;
        return ok;
    }
    
    bool FITKAbaqusAdaptorInteractionProperty::writeInteractionPropertyContact()
    {
        //通过工厂创建
        auto adaptor = new FITKAbaqusAdaptorInteractionPropertySurfaceContact;
        if (adaptor == nullptr)
        {
            return false;
        }
        //设置读取器
        adaptor->setFileWriter(_writer);
        adaptor->setDataObject(_dataObj);
        adaptor->setCaseData(_caseData);
        bool ok = adaptor->adaptW();

        delete adaptor;
        return ok;
    }
}